<%@page import="ca.qc.bdeb.info.pp2.tp2.application.ImageAgentBean"%>
<%@page import="java.io.OutputStream"%>
<%@page import="ca.qc.bdeb.info.pp2.tp2.application.ImageProprieteBean"%>
<%@page import="ca.qc.bdeb.info.pp2.tp2.application.Facade"%>
<%@page import="ca.qc.bdeb.info.pp2.tp2.controleur.ConstantesWeb"%>
<%@page errorPage="error.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
    Facade f = new Facade();
    int id;
    ImageProprieteBean ip = null;
    ImageAgentBean ia = null;

    if (request.getParameter(ConstantesWeb.VALEUR_ID_PROPRIETE) != null) {
        id = Integer.parseInt(request.getParameter(ConstantesWeb.VALEUR_ID_PROPRIETE));
        ip = f.getImageProprietePrincipale(id);

        if (ip != null) {
            response.setContentType(ip.getMimetype());
            OutputStream o = response.getOutputStream();
            o.write(ip.getImageAlbum().getBytes(1, (int) ip.getImageAlbum().length()));
            o.flush();
            o.close();
        }
    } else if (request.getParameter(ConstantesWeb.VALEUR_ID_IMAGE_PROPRIETE_SECONDAIRE) != null) {
        id = Integer.parseInt(request.getParameter(ConstantesWeb.VALEUR_ID_IMAGE_PROPRIETE_SECONDAIRE));
        ip = f.getImageProprieteSecondaire(id);

        if (ip != null) {
            response.setContentType(ip.getMimetype());
            OutputStream o = response.getOutputStream();
            o.write(ip.getImageAlbum().getBytes(1, (int) ip.getImageAlbum().length()));
            o.flush();
            o.close();
        }
        
        
        
        
        
        
    } else {
        id = Integer.parseInt(request.getParameter(ConstantesWeb.VALEUR_ID_AGENT));
        ia = f.getImageAgent(id);

        response.setContentType(ia.getMimetype());
        OutputStream o = response.getOutputStream();
        o.write(ia.getImageAlbum().getBytes(1, (int) ia.getImageAlbum().length()));
        o.flush();
        o.close();
    }


%>
